/////// comments ///////

#include <cstring>
#include <iostream>
#include <map>
#include <vector>
#include "combined.h"
#include "command.h"
#include "commandTable.h"
#include "definitions.h"
#include "log.h"
#include "stringutil.h"
#include "timestamp.h"
#include "tEditHandler.h"
#include "world.h"

// Command definitions for commands beginning with the letters A through F
// (Keep in alphabetical order... it's MUCH easier)
CmdAedit::CmdAedit( void ) {
	setName( "aedit" );
	setLevel( GOD );
	setEnabled( true );
	setOmniset( true );
	setTags( "aedit immortal" );
	addSyntax( "syntax: aedit    {Center aedit mode" );
	addHelp( "aedit mode is the Symphony Edit Mode (SEM) for Areas, where you" );
	addHelp( "are able to create, modify, and delete areas on the fly." );
}

bool CmdAedit::execute( Character* character, const std::string& args ) {

	character->setStatus( AEDIT );
	character->Send( "Welcome to the Symphony Editor for Areas (SEA)!" );

	return true;
}

CmdAlist::CmdAlist( void ) {
	setName( "alist" );
	setLevel( 1 );
	setEnabled( true );
	setOmniset( false );
	setTags( "alist area list" );
	addSyntax( "syntax: alist            {Clists all areas" );
	addSyntax( "        alist <string>   {Clists any areas containing <string>" );
}

bool CmdAlist::execute( Character* character, const std::string& args ) {
	std::string input = lowerString( trim( args ) );
	std::string buf;
	unsigned i = 0;

	if ( args.empty() ) {
		for ( std::map<std::string,Area*>::iterator it = World::Instance().getAreas().begin(); it != World::Instance().getAreas().end(); ++it, ++i ) {
			buf << "\n\r [" << i+1 << "] ";
			if ( i < 10 )
				buf << "  ";
			if ( i < 100 )
				buf << " ";
			if ( character->getLevel() >= BUILDER ) {
				buf << (*it).second->getFirstv() << " - " << (*it).second->getLastv() << '\t';
				if ( (*it).second->getLastv() < 100 )
					buf << '\t';
			}
			buf << (*it).second->getName();
		}
	} else {
		for ( std::map<std::string,Area*>::iterator it = World::Instance().getAreas().begin(); it != World::Instance().getAreas().end(); ++it, ++i ) {
			if ( strstr( lowerString((*it).second->getName()), input ) ) {
				buf << "\n\r [" << i+1 << "] ";
				if ( i < 10 )
					buf << "  ";
				if ( i < 100 )
					buf << " ";
				if ( character->getLevel() >= BUILDER ) {
					buf << (*it).second->getFirstv() << " - " << (*it).second->getLastv() << '\t';
					if ( (*it).second->getFirstv() < 100 )
						buf << '\t';
				}
				buf << (*it).second->getName();
			}
		}
	}

	character->Send( buf );

	return true;
}

CmdAsave::CmdAsave( void ) {
	setName( "asave" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( true );
	setTags( "asave save" );
	addSyntax( "syntax: asave     {Csaves all system data" );
	addHelp( "This command will save all current server & system data including:" );
	addHelp( "    -areas" );
	addHelp( "    -pfiles" );
	addHelp( "    -help files" );
	addHelp( "    -boards & notes" );
}

bool CmdAsave::execute( Character* character, const std::string& args ) {
	std::string buf;

	World::Instance().save();
	buf << "World data saved " << Timestamp::Instance().getDateTime();
	character->Send( buf );

	return true;
}

CmdAt::CmdAt( void ) {
	setName( "at" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	//setTags( "" );
	addSyntax( "syntax at <vnum> <command>   {Cperform the given command in the given room" );
	addHelp( "The <command> argument is almost any command you could want to execute," );
	addHelp( "except it executes the command as if you were in the specified room." );
	addHelp( "\"at\" does not move you from the current room." );
}

bool CmdAt::execute( Character* character, const std::string& args ) {
	std::string s_vnum, input;
	split( args, s_vnum, input );
	s_vnum = trim( s_vnum );
	unsigned vnum = 0;
	Character* target = NULL;
	Room* saved = character->getRoom();
	Room* at = NULL;

	if ( s_vnum.empty() || input.empty() ) {
		character->Send( getSyntax() );
		return false;
	}

	if ( isdigit( s_vnum[0] ) ) {
		vnum = atoi( s_vnum.c_str() );
		if ( ( at = World::Instance().getRoom( vnum ) ) == NULL ) {
			character->Send( "Invalid vnum." );
			return false;
		}
	} else {
		if ( ( target = World::Instance().getCharacter( s_vnum ) ) == NULL ) {
			character->Send( "That target could not be found." );
			return false;
		}
		at = target->getRoom();
	}

	saved->drop( character );
	at->add( character );
	character->setRoom( at );
	CommandTable::Instance().execute( character, input );
	at->drop( character );
	saved->add( character );
	character->setRoom( saved );

	return true;
}

CmdBoards::CmdBoards( void ) {
	setName( "boards" );
	setLevel( 1 );
	setEnabled( true );
	setOmniset( false );
	setTags( "board note message" );
	addSyntax( "syntax: boards                {Clists all boards" );
	addSyntax( "        board <number>        {Cselects a board" );
	addSyntax( "        board list            {Clists all posts on the currently selected board" );
	addSyntax( "        board read <number>   {Cread a note on the currenly selected board" );
}

bool CmdBoards::execute( Character* character, const std::string& args ) {
	std::string buf;
	std::string tmp;
	std::string arg1, arg2;
	unsigned i = 0;

	split( args, arg1, arg2 );

	if ( arg1.empty() ) {
		buf << "\t{!WBoards{x\n\r\n\r";
		for ( std::vector< Board* >::iterator b_it = World::Instance().getBoards().begin(); b_it != World::Instance().getBoards().end(); ++b_it ) {
			buf << "\n\r" << format( 2, (*b_it)->getNumber(), tmp, 'Y' ) << ": ";
			if ( character->getBoard() == (*b_it) )
				buf << format( 10, (*b_it)->getName(), tmp, 'Y' );
			else
				buf << format( 10, (*b_it)->getName(), tmp, 'y' );
			buf << " ({g" << (*b_it)->getNotes().size() << "{x)";
		}
		character->Send( buf );
		return true;
	} else if ( arg1 == "list" ) {
		if ( character->getBoard() == NULL ) {
			character->Send( "You must select a board first." );
			return false;
		} else {
			for ( std::vector< Note* >::iterator n_it = character->getBoard()->getNotes().begin(); n_it != character->getBoard()->getNotes().end(); ++n_it ) {
				buf << "\n\r" << format( 4, (*n_it)->getId(), tmp, 'Y' );
				buf << format( 20, (*n_it)->getAuthor(), tmp, 'y' ) << " [ {R";
				buf << (*n_it)->getSubject() << "{x ]";
			}
			character->Send( buf );
			return true;
		}
	} else if ( arg1 == "read" ) {
		if ( character->getBoard() == 0 ) {
			character->Send( "You must select a board first." );
			return false;
		} else {
			unsigned note = atoi( arg2.c_str() );
			for ( std::vector< Note* >::iterator n_it = character->getBoard()->getNotes().begin(); n_it != character->getBoard()->getNotes().end(); ++n_it ) {
				if ( (*n_it)->getId() == note ) {
					buf << "Author:    {C" << (*n_it)->getAuthor() << "{x\n\r";
					buf << "Recipient: {C" << (*n_it)->getRecipient() << "{x\n\r";
					buf << "Subject:   {C" << (*n_it)->getSubject() << "{x\n\r";
					buf << "Sent:      {C" << (*n_it)->getSent() << "{x\n\r";
					buf << (*n_it)->getBody();
					character->Send( buf );
					return true;
				}
			}
		}
	} else {
		i = atoi( args.c_str() );
		for ( std::vector< Board* >::iterator b_it = World::Instance().getBoards().begin(); b_it != World::Instance().getBoards().end(); ++b_it ) {
			if ( (*b_it)->getNumber() == i ) {
				character->setBoard( *b_it );
				character->Send( "You've selected the " + character->getBoard()->getName() + " board." );
				return true;
			}
		}
		if ( character->getBoard() == NULL ) {
			character->Send( "Invalid board number." );
			return false;
		}
	}

	return false;
}

CmdBuzz::CmdBuzz( ) {
	setName( "buzz" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "buzz alarm alert" );
	addSyntax( "syntax: buzz <name>     {Cbuzzes the target" );
}

bool CmdBuzz::execute( Character* character, const std::string& args ) {
	std::string name = trim( args );
	std::string message;
	Character* target = NULL;

	if ( name.empty() ) {
		character->Send( getSyntax() );
		return false;
	}
	if ( ( target = World::Instance().getCharacter( name ) ) == NULL ) {
		character->Send( "That target cannot be found." );
		return false;
	}
	if ( target == character ) {
		character->Send( "Why would you buzz yourself?" );
		return false;
	}

	target->Send( "\n\r{RYou have been buzzed by {W" + character->getName() + "{R!" );
	character->Send( "Your target has been buzzed!" );

	return true;
}

CmdClear::CmdClear( void ) {
	setName( "clear" );
	setLevel( 1 );
	setEnabled( true );
	setOmniset( false );
	setTags( "clear screen display output" );
	addSyntax( "syntax: clear       {CScrolls down to give you a blank screen" );
}

bool CmdClear::execute( Character* character, const std::string& args ) {
	std::string buf;
	for ( unsigned u=0; u < 40; u++ )
		buf << "\n\r";
	character->Send( buf );
	return true;
}

CmdClose::CmdClose( void ) {
	setName( "close" );
	setLevel( 1 );
	setEnabled( true );
	setOmniset( false );
	setTags( "close open door lock" );
	addSyntax( "syntax: close <direction>     {Ccloses the <direction> door" );
	addSyntax( "        close <container>     {Ccloses <container>" );
}

bool CmdClose::execute( Character* character, const std::string& args ) {
	std::string buf;

	if ( args.empty() ) {
		character->Send( "Which door do you wish to close?" );
		return false;
	}

	if ( strcmp( args.c_str(), "north" ) == 0 || strcmp( args.c_str(), "n" ) == 0 ) {
		if ( !character->getRoom()->getExit( NORTH )->getThere() ) {
			character->Send( "There is no door that way." );
			return false;
		}
		if ( !character->getRoom()->getExit( NORTH )->getDoor() ) {
			character->Send( "There is no door that way." );
			return false;
		}
		if ( !character->getRoom()->getExit( NORTH )->getOpen() ) {
			character->Send( "That door is already closed." );
			return false;
		}
		character->getRoom()->getExit( NORTH )->setOpen( false );
		World::Instance().getRoom( character->getRoom()->getExit( NORTH )->getPoint() )->getExit( SOUTH )->setOpen( false );
		character->Send( "You have closed the door." );
		return true;
	}
	if ( strcmp( args.c_str(), "east" ) == 0 || strcmp( args.c_str(), "e" ) == 0 ) {
		if ( !character->getRoom()->getExit( EAST )->getThere() ) {
			character->Send( "There is no door that way." );
			return false;
		}
		if ( !character->getRoom()->getExit( EAST )->getDoor() ) {
			character->Send( "There is no door that way." );
			return false;
		}
		if ( !character->getRoom()->getExit( EAST )->getOpen() ) {
			character->Send( "That door is already closed." );
			return false;
		}
		character->getRoom()->getExit( EAST )->setOpen( false );
		World::Instance().getRoom( character->getRoom()->getExit( EAST )->getPoint() )->getExit( WEST )->setOpen( false );
		character->Send( "You have closed the door." );
		return true;
	}
	if ( strcmp( args.c_str(), "south" ) == 0 || strcmp( args.c_str(), "s" ) == 0 ) {
		if ( !character->getRoom()->getExit( SOUTH )->getThere() ) {
			character->Send( "There is no door that way." );
			return false;
		}
		if ( !character->getRoom()->getExit( SOUTH )->getDoor() ) {
			character->Send( "There is no door that way." );
			return false;
		}
		if ( !character->getRoom()->getExit( SOUTH )->getOpen() ) {
			character->Send( "That door is already closed." );
			return false;
		}
		character->getRoom()->getExit( SOUTH )->setOpen( false );
		World::Instance().getRoom( character->getRoom()->getExit( SOUTH )->getPoint() )->getExit( NORTH )->setOpen( false );
		character->Send( "You have closed the door." );
		return true;
	}
	if ( strcmp( args.c_str(), "west" ) == 0 || strcmp( args.c_str(), "w" ) == 0 ) {
		if ( !character->getRoom()->getExit( WEST )->getThere() ) {
			character->Send( "There is no door that way." );
			return false;
		}
		if ( !character->getRoom()->getExit( WEST )->getDoor() ) {
			character->Send( "There is no door that way." );
			return false;
		}
		if ( !character->getRoom()->getExit( WEST )->getOpen() ) {
			character->Send( "That door is already closed." );
			return false;
		}
		character->getRoom()->getExit( WEST )->setOpen( false );
		World::Instance().getRoom( character->getRoom()->getExit( WEST )->getPoint() )->getExit( EAST )->setOpen( false );
		character->Send( "You have closed the door." );
		return true;
	}
	if ( strcmp( args.c_str(), "up" ) == 0 || strcmp( args.c_str(), "u" ) == 0 ) {
		if ( !character->getRoom()->getExit( UP )->getThere() ) {
			character->Send( "There is no door that way." );
			return false;
		}
		if ( !character->getRoom()->getExit( UP )->getDoor() ) {
			character->Send( "There is no door that way." );
			return false;
		}
		if ( !character->getRoom()->getExit( UP )->getOpen() ) {
			character->Send( "That door is already closed." );
			return false;
		}
		character->getRoom()->getExit( UP )->setOpen( false );
		World::Instance().getRoom( character->getRoom()->getExit( UP )->getPoint() )->getExit( DOWN )->setOpen( false );
		character->Send( "You have closed the door." );
		return true;
	}
	if ( strcmp( args.c_str(), "down" ) == 0 || strcmp( args.c_str(), "d" ) == 0 ) {
		if ( !character->getRoom()->getExit( DOWN )->getThere() ) {
			character->Send( "There is no door that way." );
			return false;
		}
		if ( !character->getRoom()->getExit( DOWN )->getDoor() ) {
			character->Send( "There is no door that way." );
			return false;
		}
		if ( !character->getRoom()->getExit( DOWN )->getOpen() ) {
			character->Send( "That door is already closed." );
			return false;
		}
		character->getRoom()->getExit( DOWN )->setOpen( false );
		World::Instance().getRoom( character->getRoom()->getExit( DOWN )->getPoint() )->getExit( UP )->setOpen( false );
		character->Send( "You have closed the door." );
		return true;
	}
	return false;
}

CmdColors::CmdColors( void ) {
	setName( "colors" );
	setLevel( 1 );
	setEnabled( true );
	setOmniset( false );
	setTags( "color output print format" );
	addSyntax( "syntax: colors    {CDisplays the possible color sequences" );
	addHelp( "To utilize color codes, place an open curly brace \"{\" before" );
	addHelp( "the letter corresponding to the desired color. For example, if" );
	addHelp( "you want red text, you would need to type {{R<sample text>, which" );
	addHelp( "yields {R<sample text>{x.  The color escape sequence for default" );
	addHelp( "terminal color is \"{{x\".  Any character after an open curly" );
	addHelp( "brace will be interpreted as a color escape sequence, therefore," );
	addHelp( "to display a \"{{\", you need to type \"{{{{\"." );
}

bool CmdColors::execute( Character* character, const std::string& args ) {
	std::string buf;

	buf << "Color table:\n\r";
	buf << "\t{{r  -{rdark red\n\r";
	buf << "\t{{R  -{Rbright red\n\r";
	buf << "\t{{g  -{gdark green\n\r";
	buf << "\t{{G  -{Gbright green\n\r";
	buf << "\t{{b  -{bdark blue\n\r";
	buf << "\t{{B  -{Bbright blue\n\r";
	buf << "\t{{y  -{ydark yellow/brown\n\r";
	buf << "\t{{Y  -{Ybright yellow\n\r";
	buf << "\t{{m  -{mdark magenta\n\r";
	buf << "\t{{M  -{Mbright magenta\n\r";
	buf << "\t{{c  -{cdark cyan\n\r";
	buf << "\t{{C  -{Cbright cyan\n\r";
	buf << "\t{{w  -{wdark grey/black\n\r";
	buf << "\t{{W  -{Wwhite\n\r";
	buf << "\t{{x  -{xdefault";

	character->Send( buf );

	return true;
}

CmdCommands::CmdCommands( ) {
	setName( "commands" );
	setLevel( 1 );
	setEnabled( true );
	setOmniset( false );
	setTags( "command list" );
	addSyntax( "syntax: commands    {CDisplays all current commands" );
	addHelp( "\"Commands\" will display a table of all currently available" );
	addHelp( "commands.  Any commands which are disabled will be displayed," );
	addHelp( "however will appear in {wdarker{x text." );
}

bool CmdCommands::execute( Character* character, const std::string& args ) {
	std::string buf;
	std::string temp;
	unsigned i=0;

	// HEAD Commands...
	if ( character->getLevel() >= HEAD ) {
		buf << "\n\r\t{cHead commands:{x\n\r";
		for ( std::vector< Command* >::iterator it = CommandTable::Instance().getCommands().begin(); it != CommandTable::Instance().getCommands().end(); ++it ) {
			if ( (*it)->getLevel() == HEAD ) {
				if ( i % 6 == 0 ) {
					if ( i )
						buf << "\n\r";
					buf << "  ";
				}
				if ( (*it)->getEnabled() )
					buf << format( 12, (*it)->getName(), temp );
				else
					buf << format( 12, (*it)->getName(), temp, 'w' );
				i++;
			}
		}
	}

	// GOD Commands...
	if ( character->getLevel() >= GOD ) {
		i = 0;
		buf << "\n\r\t{cGod commands:{x\n\r";
		for ( std::vector< Command* >::iterator it = CommandTable::Instance().getCommands().begin(); it != CommandTable::Instance().getCommands().end(); ++it ) {
			if ( (*it)->getLevel() == GOD ) {
				if ( i % 6 == 0 ) {
					if ( i )
						buf << "\n\r";
					buf << "  ";
				}
				if ( (*it)->getEnabled() )
					buf << format( 12, (*it)->getName(), temp );
				else
					buf << format( 12, (*it)->getName(), temp, 'w' );
				i++;
			}
		}
	}

	// BUILDER Commands...
	if ( character->getLevel() >= BUILDER ) {
		i = 0;
		buf << "\n\r\t{cBuilder commands:{x\n\r";
		for ( std::vector< Command* >::iterator it = CommandTable::Instance().getCommands().begin(); it != CommandTable::Instance().getCommands().end(); ++it ) {
			if ( (*it)->getLevel() == BUILDER ) {
				if ( i % 6 == 0 ) {
					if ( i )
						buf << "\n\r";
					buf << "  ";
				}
				if ( (*it)->getEnabled() )
					buf << format( 12, (*it)->getName(), temp );
				else
					buf << format( 12, (*it)->getName(), temp, 'w' );
				i++;
			}
		}
	}

	// KING Commands...
	if ( character->getLevel() >= KING ) {
		i = 0;
		buf << "\n\r\t{cKing commands:{x\n\r";
		for ( std::vector< Command* >::iterator it = CommandTable::Instance().getCommands().begin(); it != CommandTable::Instance().getCommands().end(); ++it ) {
			if ( (*it)->getLevel() == KING ) {
				if ( i % 6 == 0 ) {
					if ( i )
						buf << "\n\r";
					buf << "  ";
				}
				if ( (*it)->getEnabled() )
					buf << format( 12, (*it)->getName(), temp );
				else
					buf << format( 12, (*it)->getName(), temp, 'w' );
				i++;
			}
		}
	}

	// LORD Commands...
	if ( character->getLevel() >= LORD ) {
		i = 0;
		buf << "\n\r\t{cLord commands:{x\n\r";
		for ( std::vector< Command* >::iterator it = CommandTable::Instance().getCommands().begin(); it != CommandTable::Instance().getCommands().end(); ++it ) {
			if ( (*it)->getLevel() == LORD ) {
				if ( i % 6 == 0 ) {
					if ( i )
						buf << "\n\r";
					buf << "  ";
				}
				if ( (*it)->getEnabled() )
					buf << format( 12, (*it)->getName(), temp );
				else
					buf << format( 12, (*it)->getName(), temp, 'w' );
				i++;
			}
		}
	}

	// Regular Commands...
	buf << "\n\r\t{c-- Commands --{x \n\r";
	i = 0;
	for ( std::vector< Command* >::iterator it = CommandTable::Instance().getCommands().begin(); it != CommandTable::Instance().getCommands().end(); ++it ) {
		if ( (*it)->getLevel() == 1 ) {
			if ( i % 6 == 0 ) {
				if ( i )
					buf << "\n\r";
				buf << "  ";
			}
			if ( (*it)->getEnabled() )
				buf << format( 12, (*it)->getName(), temp );
			else
				buf << format( 12, (*it)->getName(), temp, 'w' );
			i++;
		}
	}

	character->Send( buf );

	return true;
}

CmdDemote::CmdDemote( void ) {
	setName( "demote" );
	setLevel( GOD );
	setEnabled( true );
	setOmniset( true );
	setTags( "demote promote" );
	addSyntax( "syntax: demote <name> <level>    {CDemotes target character to the given level" );
	addHelp( "You cannot demote a target whose level is not at least three below your own." );
}

bool CmdDemote::execute( Character* character, const std::string& args ) {
	std::string buf;
	std::string buf2;
	std::string name;
	std::string sLevel;
	unsigned level = 0;
	Character* target = NULL;

	split( args, name, sLevel );

	if ( name.empty() || sLevel.empty() ) {
		character->Send( " >> \"demote\" decreases a characters' level.\n\rsyntax: promote <character name> <level>" );
		return false;
	}

	level = atoi( sLevel.c_str() );
	if ( ( target = World::Instance().getCharacter( name ) ) == NULL ) {
		character->Send( "That target cannot be found." );
		return false;
	}

	if ( target->getLevel() <= level ) {
		character->Send( "That wouldn't be a demotion." );
		return false;
	}

	if ( character->getLevel() <= target->getLevel() + 2 || character->getLevel() <= level + 2 ) {
		character->Send( "You do not have permission to do that." );
		return false;
	}

	target->setLevel( level );

	buf << "You have demoted " << target->getName() << " to level " << target->getLevel() << "!";
	buf2 << character->getName() << " has {Rdemoted{x you to level {w" << target->getLevel() << "{x!";

	character->Send( buf );
	target->Send( buf2 );

	return true;
}

CmdDescription::CmdDescription( void ) {
	setName( "description" );
	setLevel( 1 );
	setEnabled( true );
	setOmniset( false );
	setTags( "description" );
	addSyntax( "syntax: description       {CDisplays your current description" );
	addSyntax( "        description edit  {Cedits your description" );
}

bool CmdDescription::execute( Character* character, const std::string& args ) {
	std::string input = trim( args );
	std::string buf;

	// Display current description...
	if ( input.empty() ) {
		character->Send( character->getFullDesc() );
		return true;
	}

	// Send them to edit their description...
	if ( input == "edit" ) {
		character->setTedit( true );
		tEditList::Instance().act( character, input );
		return true;
	}

	// Unrecognized arguments...
	character->Send( getSyntax() );
	return false;
}

CmdDisable::CmdDisable( void ) {
	setName( "disable" );
	setLevel( HEAD );
	setEnabled( true );
	setOmniset( true );
	setTags( "disable enable" );
	addSyntax( "syntax: disable <name>     {CDisables command <name> from use" );
	std::string help;
	help << "You cannot disable head (level " << HEAD << ") commands.";
	addHelp( help );
}

bool CmdDisable::execute( Character* character, const std::string& args ) {
	std::string buf;
	std::string command = args;

	if ( args.empty() ) {
		character->Send( " >> \"disable\" disables a command from use.\n\r\n\rsyntax: disable <command name>" );
		return true;
	}

	for ( std::vector< Command* >::iterator it = CommandTable::Instance().getCommands().begin(); it != CommandTable::Instance().getCommands().end(); ++it ) {
		if ( (*it)->getName() == command ) {
			if ( (*it)->getLevel() == HEAD ) {
				buf << "Level " << HEAD << " commands cannot be disabled.";
				character->Send( buf );
				return false;
			}
			if ( !(*it)->getEnabled() ) {
				buf << (*it)->getName() << " is already disabled.";
				character->Send( buf );
				return false;
			} else {
				// Disable the command...
				(*it)->setEnabled( false );
				buf << (*it)->getName() << " has been disabled.";
				character->Send( buf );
				// Log the event...
				log( character->getName() + " disabled the command \"" + (*it)->getName() + "\"", WORLD );
				character->record( " disabled the command \"" + (*it)->getName() + "\"" );
				return true;
			}
		}
	}

	character->Send( "That command was not found." );

	return false;
}

CmdDisconnect::CmdDisconnect( ) {
	setName( "disconnect" );
	setLevel( GOD );
	setEnabled( true );
	setOmniset( true );
	setTags( "disconnect socket" );
	addSyntax( "syntax: disconnect <name>    {CDisconnects the target from the server" );
	addHelp( "Disconnect will terminate the target players' connection, after saving" );
	addHelp( "their pfile data." );
}

bool CmdDisconnect::execute( Character* character, const std::string& args ) {
	std::string s_target;
	std::string arguments;
	Character* target = NULL;

	if ( args.empty() ) {
		character->Send( "Syntax: disconnect <player>" );
		return false;
	}
	
	split ( args, s_target, arguments );
	
	if ( ( target = World::Instance().getCharacter( s_target ) ) == NULL ) {
		character->Send( "That target cannot be found." );
		return false;
	}

	target->setDisconnected( true );
	character->Send( "Your target has been disconnected." );

	return true;
}

CmdDown::CmdDown( void ) {
	setName( "down" );
	setLevel( 1 );
	setEnabled( true );
	setOmniset( false );
	setTags( "north east south west up down move direction" );
	addSyntax( "syntax: down      {Cmove downward" );
}

bool CmdDown::execute( Character* character, const std::string& args ) {
	std::string buf;
	Exit* in = character->getRoom()->getExit( DOWN );

	if ( !in->getThere() ) {
		character->Send( "There is no exit that way." );
		return false;
	} else if ( in->getDoor() && !in->getOpen() ) {
		character->Send( "That door is closed." );
		return false;
	} else {
		Room* from = character->getRoom();
		Room* to = NULL;
		if ( ( to = World::Instance().getRoom( in->getPoint() ) ) == NULL ) {
			character->Send( "You can't go there." );
			std::string message = "Exit inconsistency: ";
			message << from->getVnum() << " down to " << in->getPoint();
			log( message, WORLD );
			return false;
		}

		from->drop( character );
		from->send( character->getName() + " has left going down." );
		to->send( character->getName() + " has left going down." );
		to->add( character );
		character->setRoom( to );

		// Force the "look" Command...
		std::string empty;
		CmdLook commandLook;
		commandLook.execute( character, empty );
	}

	return true;
}

CmdDrop::CmdDrop( void ) {
	setName( "drop" );
	setLevel( 1 );	
	setEnabled( true );
	setOmniset( false );
	setTags( "drop get give take put object" );
	addSyntax( "syntax: drop <name>     {Cdrop target item to the ground" );
}

bool CmdDrop::execute( Character* character, const std::string& args ) {
	std::string charBuf;
	std::string roomBuf;
	Object* object = NULL;

	if ( args == "all" ) {
		for ( std::vector< Object* >::iterator it = character->getInventory().begin(); character->getInventory().size() != 0; it = character->getInventory().begin() ) {
			character->getRoom()->add( *it );
			character->drop( *it );
			roomBuf << "\n\r" << character->getName() << " drops " << (*it)->getShortDesc() << "{x.";
			charBuf << "\n\rYou drop " << (*it)->getShortDesc() << "{x.";
		}
		character->getRoom()->send( roomBuf );
		character->Send( charBuf );
		return true;
	}

	if ( ( object = character->Creature::getObject( args ) ) == NULL ) {
		character->Send( "You don't have " + args + "." );
		return false;
	} else {
		character->getRoom()->add( object );
		character->drop( object );
		roomBuf << character->getName() << " drops " << object->getShortDesc() << "{x.";
		charBuf << "You drop " << object->getShortDesc() << "{x.";
		character->getRoom()->send( roomBuf );
		character->Send( charBuf );
		return true;
	}

	return false;
}

CmdEast::CmdEast( void ) {
	setName( "east" );
	setLevel( 1 );
	setEnabled( true );
	setOmniset( false );
	setTags( "north east south west up down move direction" );
	addSyntax( "syntax: east      {Cmove eastward" );
}

bool CmdEast::execute( Character* character, const std::string& args ) {
	std::string buf;
	Exit* in = character->getRoom()->getExit( EAST );
	
	if ( !in->getThere() ) {
		buf << "There is no exit that way.";
		character->Send( buf );
		return false;
	} else if ( in->getDoor() && !in->getOpen() ) {
		buf << "That door is closed.";
		character->Send( buf );
		return false;
	} else {
		Room* from = character->getRoom();
		Room* to = NULL;
		if ( ( to = World::Instance().getRoom( in->getPoint() ) ) == NULL ) {
			character->Send( "You can't go there." );
			std::string message = "Exit inconsistency: ";
			message << from->getVnum() << " east to " << in->getPoint();
			log( message, WORLD );
			return false;
		}

		from->drop( character );
		from->send( character->getName() + " has left to the east." );
		to->send( character->getName() + " has arrived from the west." );
		to->add( character );
		character->setRoom( to );

		// Force the "look" Command...
		std::string empty;
		CmdLook commandLook;
		commandLook.execute( character, empty );
	}

	return true;
}

CmdEat::CmdEat( void ) {
	setName( "eat" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "eat destroy delete remove" );
	addSyntax( "syntax: eat <mob-name>      {Cdestroys target mob" );
	addSyntax( "        eat <item-name>     {Cdestroys target object" );
	addHelp( "Eat will destroy target mob or object immediately, as well" );
	addHelp( "as any objects it holds or contains, respectively." );
}

bool CmdEat::execute( Character* character, const std::string& args ) {
	std::string buf;
	std::string roomBuf;
	std::string name = args;
	Room* room = character->getRoom();
	Mob* mob = NULL;
	Object* object = NULL;

	if ( args.empty() ) {
		character->Send( "syntax: eat <mob name | object name>" );
		return false;
	}

	// Check mobs...
	if ( ( mob = room->getMob( args ) ) != NULL ) {
		room->drop( mob );
		World::Instance().drop( mob );
		character->Send( mob->getShortDesc() + " destroyed." );
		room->send( character->getName() + " has destroyed " + mob->getShortDesc() + "." );
		delete mob;
		mob = NULL;
		return true;
	}

	// Check objects...
	if ( ( object = room->getObject( args ) ) != NULL ) {
		room->drop( object );
		World::Instance().drop( object );
		character->Send( object->getShortDesc() + " destroyed." );
		room->send( character->getName() + " has destroyed " + object->getShortDesc() + "." );
		delete object;
		object = NULL;
		return true;
	}

	character->Send( "Target not found." );
	return false;
}

CmdEmote::CmdEmote( ) {
	setName( "emote" );
	setLevel( 1 );
	setEnabled( true );
	setOmniset( false );
	setTags( "emote act role play" );
	addSyntax( "syntax: emote <string>     {Cemote to the current room" );
	addHelp( "Example usage: \"emote looks around the room.\"" );
	addHelp( "Will display to the entire room the phrase" );
	addHelp( "\"<your-name> looks around the room.\"" );
}

bool CmdEmote::execute( Character* character, const std::string& args ) {
	std::string buf;
	char buf2[MAX_BUFFER];

	if ( args.empty() ) {
		character->Send( "What do you wish to emote?" );
		return false;
	}

	if ( args[0] != ',' && args[0] != '\'' ) {
		buf2[0] = ' ';
	    strcpy( buf2+1, args.c_str() );
    } else {
	   strcpy( buf2, args.c_str() );
    }

	World::Instance().broadcast( character->getName() + buf2 );
	return true;
}

CmdEnable::CmdEnable( void ) {
	setName( "enable" );
	setLevel( HEAD );
	setEnabled( true );
	setOmniset( true );
	setTags( "enable disable command" );
	addSyntax( "syntax: enable <name>     {Cenables access to command <name>" );
}

bool CmdEnable::execute( Character* character, const std::string& args ) {
	std::string buf;
	std::string command = args;
	bool found = false;

	if ( command.empty() ) {
		character->Send( " >> \"enable\" enables a disabled command.\n\r\n\rsyntax: enable <command name>" );
		return false;
	}

	for ( std::vector< Command* >::iterator it = CommandTable::Instance().getCommands().begin(); it != CommandTable::Instance().getCommands().end(); it++ ) {
		if ( (*it)->getName() == command ) {
			if ( !(*it)->getEnabled() ) {
				// Enable the command...
				(*it)->setEnabled( true );
				buf << (*it)->getName() << " has been enabled.";
				character->record( "enabled the command \"" + (*it)->getName() + "\"" );
				log( character->getName() + " enabled the command \"" + (*it)->getName() + "\"", WORLD );
			} else {
				buf << (*it)->getName() << " is already enabled.";
			}
			found = true;
			break;
		}
	}

	if ( !found )
		buf << "That command was not found.";

	character->Send( buf );

	return true;
}

CmdForce::CmdForce( void ) {
	setName( "force" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( true );
	//setTags( "" );
	addSyntax( "syntax: force <player> <command-string>  {Cmake target player execute <command-string>" );
}

bool CmdForce::execute( Character* character, const std::string& args ) {
	std::string s_target, input;
	Character* target = NULL;

	split( args, s_target, input );

	if ( s_target.empty() || input.empty() ) {
		character->Send( getSyntax() );
		return false;
	}
	target = character->getRoom()->getCharacter( s_target );
	if ( !target )
		target = World::Instance().getCharacter( s_target );
	if ( !target ) {
		character->Send( "Target not found." );
		return false;
	}
	if ( !character->hasPermission( target ) ) {
		character->Send( "You can't force " + target->getName() + " to do anything." );
		return false;
	}

	CommandTable::Instance().execute( target, input );
	if ( character->getSocket()->GetOutput().empty() )
		character->Send( "That was easy." );
	else
		character->Send( "\n\r\n\rThat was easy." );
	return true;
}
